#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>
#include <stdlib.h>
#define ROW 10
#define COL 10

int main()
{
    srand((unsigned int)time(NULL));
    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    char matrix[ROW][COL];
    memset(matrix, '.', sizeof(matrix));
    matrix[0][0] = 'A';

    int x = 0, y = 0;
    bool flag = true;
    for(char ch = 'B'; ch <= 'Z' && flag; ch++)
    {
        flag = false;
        bool able[4];
        memset(able, 0, sizeof(able));
        for(int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < ROW && ny >= 0 && ny < COL && matrix[nx][ny] == '.')
            {
                able[i] = true;
                flag = true;
            }
        }
        while(flag)
        {
            int choice = rand() % 4;
            if(able[choice])
            {
                x += dx[choice];
                y += dy[choice];
                matrix[x][y] = ch;
                break;
            }
        }
    }
    for(int i = 0; i < ROW; i++)
    {
        for(int j = 0; j < COL; j++)
            printf("%c ", matrix[i][j]);
        printf("\n");
    }

    return 0;
}